package com.nattakute.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nattakute.dao.DepartmentDAO;
import com.nattakute.model.Department;

@Repository
public class DepartmentDAOImpl implements DepartmentDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	
	public List<Department> getDepartment() {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from Department d").list();
	}

	
	public Department getDepartmentById(Integer id) {
		Department department = null;
		try {
			department = (Department)sessionFactory.getCurrentSession().load(Department.class, id);
			return department;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	
	public Boolean addDepartment(Department department) {
		try {
			sessionFactory.getCurrentSession().save(department);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean deleteDepartment(Department department) {
		try {
			sessionFactory.getCurrentSession().delete(department);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean updateDepartment(Department department) {
		try {
			sessionFactory.getCurrentSession().update(department);
			return true;					
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

}
